﻿using UnityEngine;
using System.Text;

namespace GameBasic
{
    public class MarkdownUtil
    {
        public struct MarkReplace
        {
            public string[] head;
            // public string[] list;
        }

        public static string Process(string data, MarkReplace replace)
        {
            // string[] strArray = data.Split(new string[] { "\r\n" }, System.StringSplitOptions.RemoveEmptyEntries);
            string[] strArray = data.Split(IO.CsvData.SPLIT_LINE, System.StringSplitOptions.None);

            StringBuilder sb = new StringBuilder();

            string[] head = replace.head;

            for (int i = 0; i < strArray.Length; i++)
            {
                string s = strArray[i];
                // head
                if (s.Length > 0 && s[0] == '#')
                {
                    int start = s.IndexOf(' ');
                    s = s.Substring(start + 1);

                    //数组应有长度
                    int tempIndex = start * 2;
                    //数组长度
                    int headL = head.Length;
                    //添加的元素的序号
                    int num = headL >= tempIndex ? tempIndex - 2 : headL - 2;
                    sb.Append(head[num]).Append(s).Append(head[num + 1]).Append("\n");
                }
                else
                {
                    sb.Append(s).Append("\n");
                }
            }

            return sb.ToString();
        }
    }
}